<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="org.limp.mine.StringTool"%>
<%@ page import="jt.classic.system.ISystem" %>
<%@ page import="jt.classic.system.user.IUser" %>
<%@ page import="jt.classic.app.info.AInfoDirectory" %>
<%@ page import="java.io.*"%>
<%
   String context = jt.classic.system.ISystem.getContextPath();
   
   IUser user = ISystem.getSessionUser(request);
   
   AInfoDirectory adirec = (AInfoDirectory)request.getAttribute("adirec");
   
   String action = StringTool.checkString(request.getParameter("action"));
   
   String title = (adirec.isroot() || adirec.iparentid().equals("0"))?"专题":"栏目";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><%=title%>维护</title>
</head>
<jsp:include page="../head.jsp"></jsp:include>
<script>
   function handleFile(thizz,tp){
      var type = thizz.value.lastIndexOf(".") > 0 ? thizz.value.substring(thizz.value.lastIndexOf(".") + 1,thizz.value.length):"";
      if(type != ""){
         tp.value = type;
      }
   }

   function handleSubmit(){
      if(isblank(document.form1.idname)){
         alert("请定义<%=title%>名称");
      }else if(confirm("确定提交")){
         if(document.form1.idlabelimg){
            handleFile(document.form1.idlabelimg,document.form1.idlabelimgtype);
         }
         if(document.form1.idtitleimg){
            handleFile(document.form1.idtitleimg,document.form1.idtitleimgtype);
         }
         
         Ext.MessageBox.wait('提交修改过程中...');   
		    Ext.Ajax.request({       
		        //请求地址       
		       url: context + "/app/info.do?method=updatedirectory",       
		       //提交参数组       
		       fileUpload: true,   
		       form: 'form1',   
		       scope: 'form1',     
		       //成功时回调       
		       success: function(response, options) {       
		           //获取响应的json字符串        
		           Ext.MessageBox.hide();
		          
		           var json = response.responseText;    
                   var o= Ext.util.JSON.decode(json);
                   
                   if (o.success) {
                       Ext.Msg.alert('提示', '提交修改成功！'); 
                       var sub = parent.window;
                       sub.updateNode(o.name);
                   }else{
                       Ext.Msg.alert('提示', '提交保存失败！'); 
		           }                
		       }       
		 });
      }
   }
   
   function handleDelete(){
      if(confirm("确定删除")){
         Ext.MessageBox.wait('删除过程中...');   
		    Ext.Ajax.request({       
		        //请求地址       
		       url: context + "/app/info.do?method=deletedirectory&idid=<%=adirec.id()%>",           
		       //成功时回调       
		       success: function(response, options) {       
		           //获取响应的json字符串        
		           Ext.MessageBox.hide();
		          
		           var json = response.responseText;    
                   var o= Ext.util.JSON.decode(json);
                   
                   if (o.success) {
                       Ext.Msg.alert('提示', '删除成功！'); 
                       var sub = parent.window;
                       sub.deleteNode();
                       window.location.href = context + "/system/blank.jsp";
                   }else{
                       if(o.errCode == '0'){
                       	   Ext.Msg.alert('提示', '请先清空该栏目下的内容信息！');
                       }else{
		                   Ext.Msg.alert('提示', '删除失败！'); 
		               }
		           }                
		       }       
		 });
      }
   }
   
   function handleView(id,tp){
      var url = context + "/app/info.do?method=viewimg&id=" + id + "&type=" + tp;
      xwin(this,url,false,"图片预览");
   }
   
   function handleFace(id,key){
      var url = context + "/app/info.do?method=face2directory&id=" + id;
      //var url = context + "/app/portaltest.do?method=testtheme&key=" + key;
      xwin(this,url,false,"发布预览");
   }
   
   function handleSort(id){
       var url = context + "/app/info.do?method=sortdirectory&id=" + id;
       dialog(url, true, "栏目排序", 400, 350);

   }
   
   function handleTemplate(id){
       var url = context + "/app/infotemplate.do?method=settinglist&did=" + id;
       //dialog(url, true, "专题首页定制", 600, 350);
       window.location.href = url;
   }
</script>
<body topmargin="0" leftmargin="0">
<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="idid" value="<%=adirec.id()%>">
<input type="hidden" id="idkey" name="idkey" value="<%=adirec.ikey()%>"/>
<div style="width:600px;margin:10px;">
    <%if(!adirec.isroot()){%>
    <input type="button" value="提交修改" onclick="javascript:handleSubmit();">
    <%if(!adirec.hasChildren()){%>
    <input type="button" value="删除目录" onclick="javascript:handleDelete();">
    <%}%>
    <%}%>
    <%if(!"".equals(adirec.getResource().get("ID_TEMP"))){%>
    <!--<input type="button" class="button0" value=" 发布预览 " onclick="javascript:handleFace('<%=adirec.id()%>','<%=adirec.ikey()%>');">-->
    <%}%>
    <input type="button" onclick="javascript:window.location.href='<%=context%>/app/info.do?method=neudirectory&parent=<%=adirec.id()%>'" value=" <%if(adirec.isroot()){%>专题定义<%}else{%>添加子目录<%}%> ">
</div>
<fieldset id="lanmu" style="width:600px;margin:10px;">
<legend><%=title%>编辑</legend>
<label for="idname"><%=title%>名称  : </label>
    <%if(!adirec.isroot()){%>
    <input type="text" id="idname" name="idname" value="<%=adirec.iname()%>" style="width:410px;"/>&nbsp;<font color="red" title="必填项"><b>*</b></font>
    <%}else{%>
    <%=adirec.iname()%>
    <%}%>
<br/>
<label for="idkey">唯一标识 : </label>
    <%=adirec.ikey()%>
<br/>
  <%if(adirec.iparentid().equals("0")){%>
  <label for="idtemp">显示模板 : </label>
    <input type="text" id="idtemp" name="idtemp" value="<%=adirec.getResource().get("ID_TEMP")%>" style="width:410px;"/>
  <br/>
  <label for="idlabelimg">标识图片 : </label>
    <input type="file" id="idlabelimg" title="可作为访问专题/栏目的链接标识图片" name="idlabelimg" style="width:410px;"/>
    <input type="hidden" name="idlabelimgtype" value="<%=adirec.getResource().get("ID_LABELIMGTYPE")%>">
    <%
    if(adirec.getResource().get("ID_LABELIMG") != null && ((byte[])adirec.getResource().get("ID_LABELIMG")).length > 0){%>
    <a href="<%=adirec.getResource().get("ID_LABELIMGURL")%>" target="_blank">查看</a>
    <%}%>
  <br/>
  <label for="idtitleimg">标题图片 : </label>
    <input type="file" id="idtitleimg" title="可作为专题/栏目页面的标题图片" name="idtitleimg" style="width:410px;"/>
    <input type="hidden" name="idtitleimgtype" value="<%=adirec.getResource().get("ID_TITLEIMGTYPE")%>">
    <%if(adirec.getResource().get("ID_TITLEIMG") != null && ((byte[])adirec.getResource().get("ID_TITLEIMG")).length > 0){%>
    <a href="<%=adirec.getResource().get("ID_TITLEIMGURL")%>" target="_blank">查看</a>
    <%}%>
  <br/>
  <%}%>
  <label for="idmemo"><%=title%>说明 : </label>
    <%if(!adirec.isroot()){%>
    <textarea id="idmemo" name="idmemo"><%=adirec.imemo()%></textarea>
    <%}else{%>
    <%=adirec.imemo()%>
    <%}%>
 <br/>
</fieldset>
</form>
</body>
</html>